package br.com.fafica.sisape.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import java.awt.Font;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;

import br.com.fafica.sisape.control.ControllerMedico;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class TelaMedicoLogin extends JFrame {

	private JPanel contentPane;
	private JTextField campoUsuario;
	private JPasswordField campoSenha;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TelaMedicoLogin frame = new TelaMedicoLogin();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TelaMedicoLogin() {
		setResizable(false);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 700, 450);
		contentPane = new JPanel();
		contentPane.setBackground(new Color(255, 255, 255));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel label_1 = new JLabel("Usu\u00E1rio:");
		label_1.setHorizontalAlignment(SwingConstants.RIGHT);
		label_1.setForeground(new Color(0, 0, 128));
		label_1.setFont(new Font("Times New Roman", Font.PLAIN, 14));
		label_1.setBounds(241, 230, 46, 17);
		contentPane.add(label_1);
		
		campoUsuario = new JTextField();
		campoUsuario.setForeground(new Color(0, 0, 128));
		campoUsuario.setFont(new Font("Times New Roman", Font.PLAIN, 14));
		campoUsuario.setColumns(10);
		campoUsuario.setBounds(289, 228, 157, 23);
		contentPane.add(campoUsuario);
		
		campoSenha = new JPasswordField();
		campoSenha.setForeground(new Color(0, 0, 128));
		campoSenha.setFont(new Font("Times New Roman", Font.PLAIN, 14));
		campoSenha.setBounds(289, 255, 157, 23);
		contentPane.add(campoSenha);
		
		JLabel label_2 = new JLabel("Senha:");
		label_2.setHorizontalAlignment(SwingConstants.RIGHT);
		label_2.setForeground(new Color(0, 0, 128));
		label_2.setFont(new Font("Times New Roman", Font.PLAIN, 14));
		label_2.setBounds(241, 257, 46, 17);
		contentPane.add(label_2);
		
		JButton button = new JButton("Entrar");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String usuario = campoUsuario.getText();
				String senha = campoSenha.getText();
				ControllerMedico control = new ControllerMedico();
				boolean login = control.validarLogin(usuario, senha);
				
				if(login == true){
					TelaMedicoPrincipal telaPrincipal = new TelaMedicoPrincipal();
					telaPrincipal.setLocation(650, 0);
					telaPrincipal.setVisible(true);
					dispose();
				}else{
					TelaMensagemLogin telaMens = new TelaMensagemLogin();
					telaMens.setVisible(true);
				}
			}
		});
		button.setHorizontalTextPosition(SwingConstants.CENTER);
		button.setForeground(new Color(0, 0, 128));
		button.setFont(new Font("Times New Roman", Font.PLAIN, 14));
		button.setBounds(319, 291, 84, 25);
		contentPane.add(button);
		
		JButton button_1 = new JButton("Cadastre-se");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				TelaMedicoCadastra telaCadas = new TelaMedicoCadastra();
				telaCadas.setLocation(650, 0);
				telaCadas.setVisible(true);
			}
		});
		button_1.setHorizontalTextPosition(SwingConstants.CENTER);
		button_1.setForeground(new Color(0, 0, 128));
		button_1.setFont(new Font("Times New Roman", Font.PLAIN, 14));
		button_1.setBounds(522, 369, 121, 25);
		contentPane.add(button_1);
		
		JLabel label = new JLabel("");
		label.setIcon(new ImageIcon("arquivos\\telaLoginMedico.png"));
		label.setBounds(74, 11, 569, 179);
		contentPane.add(label);
		
		JLabel lblTerminalMdico = new JLabel("TERMINAL M\u00C9DICO");
		lblTerminalMdico.setForeground(new Color(0, 0, 128));
		lblTerminalMdico.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblTerminalMdico.setBounds(42, 46, 157, 31);
		contentPane.add(lblTerminalMdico);
	}
}
